From 61b8102dfbdbc162b4412fa219c018fc57195603 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Sep 2014 07:47:39 -0700 Subject: [PATCH] Fix cargo doc with custom build commands There's no "doc-all" profile, so it needs to be canonicalized when finding the name of the profile to pass to a build command. --- src/cargo/ops/cargo_rustc/context.rs | 9 ++++++++- src/cargo/ops/cargo_rustc/mod.rs | 4 ++-- tests/test_cargo_doc.rs | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 2cb50d397..8307ed0cd 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -22,8 +22,8 @@ pub struct Context<'a, 'b> { pub resolve: &'a Resolve, pub sources: &'a SourceMap<'b>, pub compilation: Compilation, - pub env: &'a str, + env: &'a str, host: Layout, target: Option, target_triple: String, @@ -268,6 +268,13 @@ impl<'a, 'b> Context<'a, 'b> { .expect("Should have found package") } + pub fn env(&self) -> &str { + // The "doc-all" environment just means to document everything (see + // below), but we want to canonicalize that the the "doc" profile + // environment, so do that here. + if self.env == "doc-all" {"doc"} else {self.env} + } + pub fn is_relevant_target(&self, target: &Target) -> bool { target.is_lib() && match self.env { "doc" | "test" | "bench" => target.get_profile().is_compile(), diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index ab155d31f..073110fde 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -172,11 +172,11 @@ fn compile_custom(pkg: &Package, cmd: &str, cx: &Context, first: bool) -> CargoResult { let root = cx.get_package(cx.resolve.root()); let profile = root.get_manifest().get_targets().iter() - .find(|target| target.get_profile().get_env() == cx.env) + .find(|target| target.get_profile().get_env() == cx.env()) .map(|target| target.get_profile()); let profile = match profile { Some(profile) => profile, - None => return Err(internal(format!("no profile for {}", cx.env))) + None => return Err(internal(format!("no profile for {}", cx.env()))) }; // TODO: this needs to be smarter about splitting diff --git a/tests/test_cargo_doc.rs b/tests/test_cargo_doc.rs index 71d331839..3f74f9282 100644 --- a/tests/test_cargo_doc.rs +++ b/tests/test_cargo_doc.rs @@ -12,6 +12,7 @@ test!(simple { name = "foo" version = "0.0.1" authors = [] + build = 'true' "#) .file("src/lib.rs", r#" pub fn foo() {} -- 2.30.2